SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

/* Create new stored procedures */

/*
        Powerweb Application, Cyberwolf Inc.
        Project Name:   	DISC
        Module Name:	  	DISC_Download
        SP Name:         	DISC_StampFilesInsert
        Author Name:    	Ruben Lopez
        Created on:     	01/19/2010
        Description:    	Checks if a record exists in the database. If not, inserts a new record and returns the record with the same Url and IP.

		Revision History:
		01/19/2010 Ruben Lopez: Generated
		02/10/2010 Ruben Lopez: Modified
*/
CREATE PROCEDURE [dbo].[DISC_StampFilesInsert]
	@Url nvarchar(max),
	@IP nvarchar(15),
	@FileName nvarchar(255)
AS
BEGIN
	IF NOT EXISTS(SELECT ID FROM DISC_StampFiles WHERE Url = @Url AND (IP = @IP OR IP = ''))
	BEGIN
		INSERT INTO DISC_StampFiles (ID, Url, IP, DateRequested, [Status], [FileName])
		VALUES (newid(), @Url, @IP, getdate(), 'Generating', @FileName)
	END

	SELECT ID, Url, IP, [Status], DateRequested, [FileName]
	FROM DISC_StampFiles
	WHERE Url = @Url AND (IP = @IP OR IP = '')
END
GO
